<style>
a {
	color:#000000;
    font-size:12px;
	text-decoration: none;
}
</style>
<script type="text/javascript">

	$(function() {
		$('#sysres_file_tree').tree({
			url : '${request.contextPath}${namespace?default('')}/mp/sysres/file-datagrid.json?df=${df?default('')}'
		});
	});

	function sysres_file_add() {
		var node = $('#sysres_file_tree').tree('getSelected');
		var id = '';
		
		if(node){
			if(!node.state){
				$.messager.alert('','${action.getText('file.add.warning')}','warning');
				return;
			}
			id = node.id;
		}
		$('<div>').dialog({
			href : '${request.contextPath}${namespace?default('')}/mp/sysres/file-form.htm?parentPath='+id+'&n='+Math.random(),
			width : 300,
			height : 120,
			modal : true,
			title : '${action.getText('form.add.title')}',
			buttons : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.add')}',
				iconCls : 'icon-edit',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#sys_file_Form').form('submit', {
						url : '${request.contextPath}${namespace?default('')}/mp/sysres/file-add.json',
						onSubmit: function(){
							return $(this).form('validate');
        				},
						success : function(json) {
							eval("json="+json);
							$.messager.alert(json.title,json.msg,json.level);
							d.dialog('destroy');
							$("#sysres_file_tree").tree('reload');
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
		
	}
	function sysres_file_edit() {
		var node = $('#sysres_file_tree').tree('getSelected');
		if(!node){
			$.messager.alert('',${action.getText('file.edit.warning')},'warning');
			return;
		}
		$('<div>').dialog({
			href : '${request.contextPath}${namespace?default('')}/mp/sysres/file-edit.htm?parentPath='+node.id+'&name='+node.text+'&n='+Math.random(),
			width : 300,
			height : 120,
			modal : true,
			title : '${action.getText('form.edit.title')}',
			buttons : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.edit')}',
				iconCls : 'icon-edit',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#sys_file_Form').form('submit', {
						url : '${request.contextPath}${namespace?default('')}/mp/sysres/file-update.json',
						onSubmit: function(){
							return $(this).form('validate');
        				},
						success : function(json) {
							eval("json="+json);
							$.messager.alert(json.title,json.msg,json.level);
							d.dialog('destroy');
							$("#sysres_file_tree").tree('reload');
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}
	
	function sysres_file_delete() {
		var node = $('#sysres_file_tree').tree('getSelected');
		if(!node){
			$.messager.alert('',${action.getText('file.delete.warning')},'warning');
			return;
		}
		if (node) {
			$.messager.confirm('${action.getProperty('net.esj.background.message','bg.message.info')}', '${action.getText('file.delete.ask')}', function(b) {
				if (b) {
					$.ajax({
						url : '${request.contextPath}${namespace?default('')}/mp/sysres/file-delete.json',
						data : {
							parentPath : node.id
						},
						dataType : 'JSON',
						success : function(json) {
							$.messager.alert(json.title,json.msg,json.level);
							$("#sysres_file_tree").tree('reload');
						}
					});
				}
			});
		}
	}

	function sysres_file_upload(){
		var node = $('#sysres_file_tree').tree('getSelected');
		var id = '';
		if(node){
			id = node.id;
		}
		
		$('<div>').dialog({
			href : '${request.contextPath}${namespace?default('')}/mp/sysres/file-upload.htm?action_id=${action_id}&parentPath='+id+'&n='+Math.random(),
			width : 300,
			height : 120,
			modal : true,
			title : '${action.getText('file.upload.title')}',
			buttons : [ {
				text : '${action.getText('file.upload.button')}',
				iconCls : 'icon-edit',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#upload_${action_id}').form('submit', {
						url : '${request.contextPath}${namespace?default('')}/mp/sysres/file-doUpload.htm',
						onSubmit: function(){
							return $(this).form('validate');
        				},
						success : function(json) {
							eval("json="+json);
							$.messager.alert('',json.msg,json.level);
							$("#sysres_file_tree").tree('reload');
							 d.dialog('destroy');
						}
					});
					/*$('#sys_file_uploadForm').fileUpload({
						countPercentUrl:'${request.contextPath}${namespace?default('')}/mp/sysres/file-countPercent.json',
						success:function(json){
							$.messager.alert('',json.msg,json.level);
							$("#sysres_file_tree").tree('reload');
							 d.dialog('destroy');
						}
					});*/
					
					/*var ifr = null,
			        	fm = null;
			   		//静态变量
			    	var IFRAME_NAME = 'sysres_fileUpLoadIframe';
					ifr = $('<iframe name="'+ IFRAME_NAME +'" id="'+ IFRAME_NAME +'" style="display:none;"></iframe>');
			        fm = $('#sys_file_uploadForm');
			        ifr.appendTo($('body'));
			        fm.attr('target',IFRAME_NAME); //target目标设为ifr
			        //上传完毕iframe onload事件
			        ifr.load(function(){
			            var response = this.contentWindow.document.body.innerHTML;
			            var json = $.parseJSON(response);
			            $.messager.alert(json.title,json.msg,json.level);
			            ifr.remove();
			            ifr = null; //清除引用
			            d.dialog('destroy');
						$("#sysres_file_tree").tree('reload');
			        });
			        fm.submit(); //提交表单*/
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}

	function sysres_file_download(){
		var node = $('#sysres_file_tree').tree('getSelected');
		if(node.state){
			$.messager.alert('','${action.getText('file.download.warning')}','warning');
			return;
		}
		window.open('${request.contextPath}${namespace?default('')}/mp/sysres/sysres-download.htm?path='+encodeURIComponent(node.id));
	}
</script>
<div class="easyui-layout" style="width:100%;height:100%;" border="false"  >
	<div region="north" border="false" style="padding:5px;border:1px solid #ddd;" >
		<a href="javascript:;;" onclick="sysres_file_add();" class="easyui-linkbutton" data-options="iconCls:'icon-add'">${action.getProperty('net.esj.background.message','bg.datagrid.add')}</a>
		<a href="javascript:;;" onclick="sysres_file_edit();" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">${action.getProperty('net.esj.background.message','bg.datagrid.modify')}</a>
		<a href="javascript:;;" onclick="sysres_file_delete();" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">${action.getProperty('net.esj.background.message','bg.datagrid.delete')}</a>
		<a href="javascript:;;" onclick="sysres_file_upload();" class="easyui-linkbutton" data-options="iconCls:'icon-undo'">${action.getText('file.upload.title')}</a>
		<a href="javascript:;;" onclick="sysres_file_download();" class="easyui-linkbutton" data-options="iconCls:'icon-redo'">${action.getText('file.download.title')}</a>
	</div>
	<div region="center" border="false"  >
		<ul id="sysres_file_tree"></ul> 
	</div>
</div>